<?php
/**
 * 功能说明：
 * 参数说明：
 * 返回值：
 * 备注说明：
 * 作者：Administrator
 * 最后一次修改时间:2017/5/16 16:02
 */

namespace mod;
use think\Model;
use traits\BaseQueryScope;

class DynamicPrize extends Model
{
	protected $name = 'dynamic_prize';

	public function getTypeTextAttr( $value,$data )
	{
		$status = [
			0 => '抽奖' ,
			2 => '固定'
		];
		return $status[$data['type']];
	}

	use BaseQueryScope;

	protected function scopeLuckydraw($query)
	{
		$query->where('type',0)->field('travel_id,prize_coupon_code,starttime,endtime,type,CASE WHEN endtime < now() THEN 0 ELSE 1 END as sort')->order('sort desc,id desc');
	}

	protected function scopeFixed($query)
	{
		$query->where('type',2)->field('travel_id,prize_coupon_code,starttime,endtime,type,CASE WHEN endtime < now() THEN 0 ELSE 1 END as sort')->order('sort desc,endtime asc');
	}

}